package ttt;

import bean.Iterator;
import com.mysql.cj.util.StringUtils;

import java.lang.reflect.Array;
import java.security.InvalidParameterException;
import java.sql.SQLException;
import java.util.*;

public class Eachdata {

    public Eachdata(Map<String, ArrayList> map1,Map<String, ArrayList> map2,Iterator iterator) throws SQLException {

        int it = Math.toIntExact((Long) iterator.getId());

        //遍历  数据对比
        Set<String> keySet = map1.keySet();
        for (String key : keySet){

            iterator.setId((long) it);
//            System.out.println("迭代开始："+iterator);
            ArrayList arrayList1 = map1.get(key);
            ArrayList arrayList2 = map1.get(map1.get(key).get(1));

            if (Arrays.equals(new ArrayList[]{arrayList1},new ArrayList[]{arrayList2})){

//                try {
                    //对比基础数据

                    //对比身份等级
                    OKvoiceUser oKvoiceUser = new OKvoiceUser();
                    Map<String, ArrayList> newMallUserMap = oKvoiceUser.selectNewMallUser(String.valueOf(arrayList1.get(1)));

                    String id = String.valueOf(arrayList1.get(1));
                    Map<String, ArrayList> stringArrayListMap2 = oKvoiceUser.selectPGUser2(id);

                if (newMallUserMap.size() == 0){
                    if (stringArrayListMap2.get("1").get(0).equals("0") || stringArrayListMap2.get("1").get(0).equals("3")){
                    }else {
                        System.out.println(newMallUserMap.get(arrayList1.get(1)).get(0)+"身份等级异常");
                        throw new InvalidParameterException("身份等级异常");
                    }
                }else if (newMallUserMap.get(arrayList1.get(1)).get(1).equals("4") || newMallUserMap.get(arrayList1.get(1)).get(1).equals("3")){
                        if (stringArrayListMap2.get("1").get(0).equals("1")){
                        }else {
                            System.out.println(newMallUserMap.get(1).get(0)+"身份等级异常");
                            throw new InvalidParameterException("身份等级异常");
                        }
                    }else if (newMallUserMap.get(arrayList1.get(1)).get(1).equals("1") || newMallUserMap.get(arrayList1.get(1)).get(1).equals("2")){
                        if (stringArrayListMap2.get("1").get(1).equals("1")){
                        }else {
                            System.out.println(newMallUserMap.get(arrayList1.get(1)).get(0)+"身份等级异常");
                            throw new InvalidParameterException("身份等级异常");
                        }
                    }else if (newMallUserMap.get(arrayList1.get(1)).get(1).equals("0")){
                        if (stringArrayListMap2.get("1").get(1).equals("0")){
                        }else {
                            System.out.println(newMallUserMap.get(arrayList1.get(1)).get(0)+"身份等级异常");
                            throw new InvalidParameterException("身份等级异常");
                        }
                        if (stringArrayListMap2.get("1").get(0).equals("0") || stringArrayListMap2.get("1").get(0).equals("3")){
                        }else {
                            System.out.println(newMallUserMap.get(arrayList1.get(1)).get(0)+"身份等级异常");
                            throw new InvalidParameterException("身份等级异常");
                        }
                    }

                    //对比封禁状态
                    String sqlStatus =  "SELECT `status` FROM c_user_ban WHERE user_id = (SELECT id FROM users WHERE ok_number = "
                        +"\""+arrayList1.get(1)+"\")";
                    String sqlStatusP = "SELECT is_ban FROM users WHERE invitation_code = "+"'"+arrayList1.get(1)+"'";
                    Map<String, Integer> statusMap = oKvoiceUser.selectUserStatus(sqlStatus);
                    Map<String, Integer> statusMapP = oKvoiceUser.selectPGUserStatus(sqlStatusP);
                    if (statusMap.get("status") == 3 && statusMapP.get("is_ban") == 0){

                    }else if (statusMap.get("status") == 1 && statusMapP.get("is_ban") == 0){

                    }else if (statusMap.get("status") == 0 && statusMapP.get("is_ban") == 1){

                    }else if (statusMap.get("status") == 3 && statusMapP.get("is_ban") == 3){

                    } else {
                        throw new InvalidParameterException("封禁状态异常"+arrayList1.get(1));
                    }


                //通过后打印输出
                    System.out.println("pass:"+iterator.getId()+"  ==  "+arrayList1.get(1)+"基础信息校验通过  "+"身份等级："
                            +newMallUserMap.get(arrayList1.get(1)).get(1)+"--"+stringArrayListMap2.get("1").get(0)
                            +"--"+stringArrayListMap2.get("1").get(1)
                            +"   封禁状态："+statusMap.get("status")+"--"+statusMapP.get("is_ban"));
                    it++;

//                }catch (NullPointerException npe){
//                    System.out.println(arrayList1.get(1)+"身份等级异常");
//                }



            }else {
                System.out.println("=========================错误数据=========================");
                System.out.println(arrayList1);
                System.out.println(arrayList2);
            }
        }
        iterator.setId((long) it);
    }
}
